import {tableData } from '@/mock/user'
import { menu } from '@/mock/menu'
import request from '@/router/axios'
import { baseUrl } from '@/config/env'
/* eslint-disable */

export const loginByUsername = (username, password, code, redomStr) => {
    return new Promise((resolve) => {
        request({
            url: `${baseUrl}/login_account`,
            method: 'post',
            data: {
                account: username,
                password: password
            }
        }).then(res =>{
            const response = res.data;
            resolve(response)
        })
    })
}

export const getUserInfo = () => {
    return new Promise((resolve) => {
        request({
            url: `${baseUrl}/me`,
            method: 'get',
        }).then(res =>{
            const response = res.data;
            if (response.status == 1){
                let data = response.result.data
                let userInfo = {
                    userInfo: {
                        username:data.nickname,
                        name:data.name,
                        avatar:data.avatar,
                        userData:data
                    },
                    roles: ['admin'],
                    permission: [
                        'sys_crud_btn_add',
                        'sys_crud_btn_export',
                        'sys_menu_btn_add',
                        'sys_menu_btn_edit',
                        'sys_menu_btn_del',
                        'sys_role_btn1',
                        'sys_role_btn2',
                        'sys_role_btn3',
                        'sys_role_btn4',
                        'sys_role_btn5',
                        'sys_role_btn6',
                    ], //权限级别
                
                }
                
                resolve({ data:userInfo})
            }
        })
        //resolve({ data: userInfo });
    })
}
export const RefeshToken = () => {
    return new Promise((resolve) => {
        resolve({ data: new Date().getTime() });
    })
}

export const getMenu = (parentId) => {
    return new Promise((resolve) => {
        if (parentId != 1) parentId = 0;
        resolve({ data: menu[parentId] });
    })
}
export const getMenuAll = () => {
    return new Promise((resolve) => {
        resolve({ data: menu[0] });
    })
}

export const getTableData = (page) => {
    console.log(page);
    return new Promise((resolve) => {
        resolve({ data: tableData });
    })
}
export const logout = () => {
    return new Promise((resolve) => {
        resolve();
    })
}